﻿namespace PMS.Client.FrmJobPosition
{
    using AdvancedDataGridView;
    using PMS.BLL;
    using PMS.Model;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Drawing;
    using System.Runtime.CompilerServices;
    using System.Windows.Forms;

    public class FrmSelect : Form
    {
        private JobPositionBLL bll = new JobPositionBLL();
        private IContainer components = null;
        private TreeGridNode node1 = null;
        private TreeGridNode node2 = null;
        private DataGridViewTextBoxColumn PositionID;
        private TreeGridColumn PositionName;
        private TreeGridView treeGridView1;

        public FrmSelect()
        {
            this.InitializeComponent();
            Font font = new Font(this.treeGridView1.DefaultCellStyle.Font, FontStyle.Bold);
            object[] values = new object[2];
            values[0] = "实配领导人";
            this.node1 = this.treeGridView1.Nodes.Add(values);
            this.node1.DefaultCellStyle.BackColor = SystemColors.Highlight;
            this.node1.DefaultCellStyle.ForeColor = Color.White;
            this.node1.DefaultCellStyle.Font = font;
            this.node1.Expand();
            values = new object[2];
            values[0] = "实配非领导人";
            this.node2 = this.treeGridView1.Nodes.Add(values);
            this.node2.DefaultCellStyle.BackColor = SystemColors.Highlight;
            this.node2.DefaultCellStyle.ForeColor = Color.White;
            this.node2.DefaultCellStyle.Font = font;
            this.node2.Expand();
            this.LoadJobPosition();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            ComponentResourceManager manager = new ComponentResourceManager(typeof(FrmSelect));
            this.treeGridView1 = new TreeGridView();
            this.PositionName = new TreeGridColumn();
            this.PositionID = new DataGridViewTextBoxColumn();
            ((ISupportInitialize) this.treeGridView1).BeginInit();
            base.SuspendLayout();
            this.treeGridView1.AllowUserToAddRows = false;
            this.treeGridView1.AllowUserToDeleteRows = false;
            this.treeGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            this.treeGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
            this.treeGridView1.BackgroundColor = Color.FromArgb(0xa4, 0xc4, 0xeb);
            this.treeGridView1.BorderStyle = BorderStyle.None;
            this.treeGridView1.Columns.AddRange(new DataGridViewColumn[] { this.PositionName, this.PositionID });
            this.treeGridView1.Dock = DockStyle.Fill;
            this.treeGridView1.EditMode = DataGridViewEditMode.EditProgrammatically;
            this.treeGridView1.EnableHeadersVisualStyles = false;
            this.treeGridView1.ImageList = null;
            this.treeGridView1.Location = new Point(0, 0);
            this.treeGridView1.Name = "treeGridView1";
            this.treeGridView1.RowHeadersVisible = false;
            this.treeGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            this.treeGridView1.Size = new Size(0x114, 0x173);
            this.treeGridView1.TabIndex = 7;
            this.treeGridView1.DoubleClick += new EventHandler(this.treeGridView1_DoubleClick);
            this.PositionName.DefaultNodeImage = null;
            this.PositionName.HeaderText = "职务名称";
            this.PositionName.Name = "PositionName";
            this.PositionName.Resizable = DataGridViewTriState.True;
            this.PositionName.SortMode = DataGridViewColumnSortMode.NotSortable;
            this.PositionID.HeaderText = "PositionID";
            this.PositionID.Name = "PositionID";
            this.PositionID.SortMode = DataGridViewColumnSortMode.NotSortable;
            this.PositionID.Visible = false;
            base.AutoScaleDimensions = new SizeF(6f, 12f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.ClientSize = new Size(0x114, 0x173);
            base.Controls.Add(this.treeGridView1);
            base.FormBorderStyle = FormBorderStyle.FixedSingle;
            base.Icon = (Icon) manager.GetObject("$this.Icon");
            base.MaximizeBox = false;
            base.MinimizeBox = false;
            base.Name = "FrmSelect";
            base.StartPosition = FormStartPosition.CenterScreen;
            this.Text = "选择职务";
            ((ISupportInitialize) this.treeGridView1).EndInit();
            base.ResumeLayout(false);
        }

        private void LoadJobPosition()
        {
            this.node1.Nodes.Clear();
            this.node2.Nodes.Clear();
            List<PMS.Model.JobPosition> list = this.bll.GetList();
            foreach (PMS.Model.JobPosition position in list)
            {
                if (position.IsLeader == 1)
                {
                    this.node1.Nodes.Add(new object[] { position.PositionName, position.PositionID });
                }
                else
                {
                    this.node2.Nodes.Add(new object[] { position.PositionName, position.PositionID });
                }
            }
        }

        private void treeGridView1_DoubleClick(object sender, EventArgs e)
        {
            if ((this.treeGridView1.SelectedRows.Count > 0) && (this.treeGridView1.SelectedRows[0].Cells[1].Value != null))
            {
                this.JobPosition = this.treeGridView1.SelectedRows[0].Cells["PositionName"].Value.ToString();
                base.DialogResult = DialogResult.OK;
                base.Close();
            }
        }

        public string JobPosition { get; set; }
    }
}

